package dynamizer;

import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;

import modele.interfaces.SimulationAbstract;

public class ClassTools {

	public void loadClass(String simulName, FileTypeEnum fileName) {
		try {

			File root = new File("./dynJavaSources/");
			URLClassLoader classLoader = URLClassLoader
					.newInstance(new URL[] { root.toURI().toURL() });
			String className = "";

			switch (fileName) {
			case SIM:
				className = simulName + "_Sim";
				break;
			case AGENTS:
				className = simulName + "_Agent";
				break;
			case CASES:
				className = simulName + "_Cases";
				break;
			// case PARAMS:
			// className = initialSimFileName + "Params";
			// break;
			default:
				// TODO A gerer
				break;
			}

			Class<? extends SimulationAbstract> myclass = (Class<? extends SimulationAbstract>) Class
					.forName(className, true, classLoader);
			// Class myclass = Class.forName(className, true, classLoader);

			SimulationAbstract object = myclass.newInstance();
			object.getDynamicData();
			// object.doSomething();

		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
}
